package world.liuru.poem.controller;
import org.springframework.web.bind.annotation.*;
import world.liuru.poem.entity.User;
import world.liuru.poem.service.UserService;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("")
    public User addUser(@RequestBody User user){
        return userService.insertUser(user);
    }

    @DeleteMapping("/{id}")
    public void deleteUser(@PathVariable("id") String id){
        userService.deleteUser(id);
    }

    @PutMapping("")
    public User updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @GetMapping("")
    public List<User> findAll(){
        return userService.findAllUser();
    }

    @GetMapping("/{id}")
    public User findById(@PathVariable("id") String id){
        return userService.findUserById(id);
    }


}
